import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import HTML from '../../utils/html-helper';
import DateHelper from '../../utils/date-helper';
import Lang from '../../lang';

class MessageDivider extends Component {

    render() {
        let {
            date,
            className,
            children,
            ...other
        } = this.props;

        let dateStr = null;
        if(date) {
            dateStr = DateHelper.formatDate(date, 'YYYY-M-d');
            if(DateHelper.isToday(date)) {
                dateStr = `${Lang.string('time.today')} ${dateStr}`;
            } else if(DateHelper.isYestoday(date)) {
                dateStr = `${Lang.string('time.yestoday')} ${dateStr}`;
            }
        }

        return <div className={HTML.classes('app-message-divider', className)} {...other}>
            <div className="content">{dateStr}{children}</div>
        </div>;
    }
}

export default MessageDivider;
